package com.refuel.response;

import io.swagger.v3.oas.annotations.media.Schema;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhanghao
 * @description
 * @date 2024/5/10 10:15
 **/
@Schema(description = "分页响应结果")
public class PageResponse<T> extends Response {

    /**
     * 页码
     */
    @Schema(description = "页码", example = "1")
    private Integer pageNo;

    /**
     * 每页数量
     */
    @Schema(description = "每页数量", example = "10")
    private Integer pageSize;

    /**
     * 泛型，返回响应数据
     */
    @Schema(description = "响应数据")
    private List<T> data;

    public PageResponse() {
        super("200", "成功");
        this.pageNo = 1;
        this.pageSize = 10;
        this.data = new ArrayList<>();
    }

    public PageResponse(String code, String desc, Integer pageNo, Integer pageSize) {
        super(code, desc);
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.data = new ArrayList<>();
    }

    /**
     * 添加商品
     */
    public void addData(T t) {
        if (this.data == null) {
            this.data = new ArrayList<>();
        }

        this.data.add(t);
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }
}
